﻿//************************************************************ 
// Copyright © 2009 - 2010 Oleg Stuhin & Rostislav Haitovich
// To learn more about Mytrip.Mvc.Entyty visit 
// http://starterkitmytripmvc.codeplex.com/
// mytripmvc@gmail.com
// license: Microsoft Public License (Ms-PL) 
// ***********************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Mytrip.Files
{
    /// <summary>
    /// File Helper
    /// </summary>
    public static class FileHelper
    {
        /// <summary>
        /// Mytrip Directory
        /// </summary>
        /// <param name="html">HtmlHelper</param>
        /// <param name="path">path</param>
        /// <returns>static string</returns>
        public static string MytripDirectory(this HtmlHelper html, string path)
        {
            string result = string.Empty;
            if (!String.IsNullOrEmpty(path))
            {
                string[] directory = path.Remove(0, 2).Replace("()", "/").Split('/');
                string _path = string.Empty; 
                foreach (string item in directory)
                {
                    if (item == directory[directory.Length - 1])
                    {
                        result += " / " + item;
                    }
                    else
                    {
                        _path += "()" + item;
                        TagBuilder _result = new TagBuilder("a");
                        _result.MergeAttribute("href", "/File/Index/" + _path);
                        _result.InnerHtml = item;
                        result += " / " + _result;
                    }
                }
            }
            return result;
        }
        /// <summary>
        /// Mytrip Mim
        /// </summary>
        /// <param name="html">HtmlHelper</param>
        /// <param name="directory">directory</param>
        /// <param name="name">name</param>
        /// <param name="extension">extension</param>
        /// <returns></returns>
        public static string MytripMim(this HtmlHelper html, string directory, string name, string extension)
        {
            string result = (directory + "/" + name).Replace("()", "/");
            if (extension != ".ico" && extension != ".png" && extension != ".jpg" && extension != ".gif")
             result = "/content/files/" + extension + ".png";
            return result;
        }
    }
}
